home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / finfo16.zip / FINFO.C next >
C/C++ Source or Header  |  1989-01-03  |  3KB  |  158 lines

  1.  
  2. /*
  3.  * finfo - dos filter update file size/date info in a file
  4.  *         directory listing.
  5.  *
  6.  * 26-feb-87 s.h.smith
  7.  *
  8.  */
  9.  
  10. #define VERSION "Finfo v1.6 01-03-89 S.H.Smith"
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <dos.h>
  15. #include <string.h>
  16.  
  17. #define ft_day    (finfo->date & 31)
  18. #define ft_month  ((finfo->date >> 5) & 15)
  19. #define ft_year   ((finfo->date >> 9) & 127)
  20. struct FIND *finfo;
  21.  
  22. void clean(char *dir, 
  23.            char *source, 
  24.            char *dest)
  25.         /* clean up a text line that might contain a filename.
  26.            if there is a legal filename, copy it to dest.  otherwise
  27.            dest will contain an empty string */
  28. {
  29.    char *s,*d;
  30.    int ifd;
  31.    char temp[255];
  32.  
  33. /* make sure source name is legal; this makes pipes from 'dir' and other
  34.    similar utilities work better */
  35.  
  36.    strcpy(temp,source);
  37.    strcat(temp,"               ");
  38.    temp[12] = 0;
  39.  
  40.    for (s=temp; (*s) && (*s != '.'); s++)
  41.       ;
  42.  
  43.    if ((temp[8] == ' ') && (*s != '.'))
  44.       temp[8] = '.';
  45.  
  46.    s = temp;
  47.    d = dest;
  48.    while (*s) 
  49.    {                   /* copy everything but spaces */
  50.       if (*s != ' ')
  51.          *d++ = *s;
  52.       s++;
  53.    }
  54.  
  55.    *d = 0;
  56.    strcpy(temp,dir);
  57.    strcat(temp,dest);
  58.  
  59. /* check the source file; if it is not valid then skip over it */
  60.  
  61.    finfo = findfirst(temp,0x21);
  62.    if (finfo == NULL) {
  63.       dest[0] = 0;
  64.       return;
  65.    }
  66. }
  67.  
  68.  
  69. char *getline(char *buf)
  70. {
  71.    char *bufstart = buf;
  72.    int i;
  73.    int c;
  74.    i = 0;
  75.  
  76.    for (;;) {
  77.       c = getchar();
  78.       if ((c == EOF) || (c == 26))
  79.          return NULL;
  80.       if ((c == '\n') || (i >= 255)) {
  81.          *buf = 0;
  82.          return bufstart;
  83.       }
  84.       if ((c != 0) && (c != '\r') && (c != 0xFF)) {
  85.          *buf++ = c;
  86.          i++;
  87.       }
  88.    }
  89. }
  90.  
  91. putln(char *s)
  92. {
  93.       while (*s)
  94.          putchar(*s++);
  95.       putchar('\n');
  96. }
  97.  
  98. main(int argc, char *argv[])
  99. {
  100.    char line[255];
  101.    char name[255];
  102.    char *rest;
  103.    char buf[BUFSIZ];
  104.    char dir[255];
  105.  
  106.    setbuf(stdout,buf);
  107.  
  108.    if (argc == 2) {
  109.       strcpy(dir,argv[1]);
  110.       if (dir[strlen(dir)-1] != '\\')
  111.          strcat(dir,"\\");
  112.    }
  113.    else {
  114.       printf("%s\n",VERSION);
  115.       printf("Usage:   finfo DIRECTORY <filelist >newlist\n");
  116.       printf("Example: finfo C:\\DL1 <C:\\PCB\\GEN\\DIR3 >DIR3.NEW\n");
  117.       exit(1);
  118.    }
  119.  
  120.  
  121. /* process all standard input lines */
  122.  
  123.    while (getline(line) != NULL) {
  124.       clean(dir,line,name);
  125.  
  126.       if (finfo == NULL)
  127.          putln(line);
  128.       else
  129.  
  130.       if ((finfo->size <= 0) ||
  131.           (ft_month < 1) || (ft_month > 12) ||
  132.           (ft_day   < 1) || (ft_day   > 31) ||
  133.           (ft_year  < 1) || (ft_year  > 30))
  134.       {
  135.          putln(line);
  136.       }
  137.       else
  138.       {
  139.          if (strlen(line) > 33)
  140.             rest = line+33;
  141.          else
  142.             rest = "";
  143.  
  144.          printf("%-12s%9ld  %02d-%02d-%02d  ",
  145.                 name,
  146.                 finfo->size,
  147.                 ft_month,
  148.                 ft_day,
  149.                 ft_year+80);
  150.          putln(rest);
  151.       }
  152.    }
  153.  
  154.    fflush(stdout);
  155. }
  156.  
  157.  
  158.